<template lang="">
    <div>
        <el-dialog title="提示" :visible.sync="dialogVisible" width="30%" :before-close="handleClose">
            <el-form label-width="80px" :model="ques">
                <el-form-item label="问卷名称">
                    <el-input v-model="ques.title"></el-input>
                </el-form-item>
                <el-form-item label="问卷描述">
                    <el-input type="textarea" :rows="2" placeholder="请输入内容" v-model="ques.describe">
                    </el-input>
                </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button @click="closeDialog">取 消</el-button>
                <el-button type="primary" @click="emitServer">确 定</el-button>
            </span>
        </el-dialog>
    </div>
</template>
<script>
    export default {                        //这是修改标题的组件，我不想改名了
        name: 'Dialog',
        data() {
            return {
                dialogVisible: false,
                ques: {
                    title: '',
                    describe: '',
                },
                conId: ''
            }
        },
        methods: {
            handleClose(done) {
                this.$confirm('确认关闭？')
                    .then(_ => {
                        done();
                    })
                    .catch(_ => { });
            },
            closeDialog() {
                this.dialogVisible = false
            },
            emitServer() {
                axios({
                    method: 'POST',
                    url: '/question/updateTitle',
                    withCredentials: true,
                    data: JSON.stringify({
                        conId: this.conId,
                        conTitle: this.ques.title,
                        conDescribe: this.ques.describe
                    }),
                    headers: {
                        'Content-Type': 'application/json'
                    }
                }).then((result) => {
                    this.$message({
                        message: '修改成功',
                        type: 'success'
                    });
                    this.closeDialog()
                    this.$bus.$emit('editTItleSuccess')
                }).catch((err) => {
                    this.$message(err.message);
                });
            }
        },
        mounted() {
            this.$bus.$on('editName', (obj) => {
                this.ques.title = obj.conTitle
                this.ques.describe = obj.conDescribe
                this.conId = obj.conId
                this.dialogVisible = true
            })
        },
        beforeDestroy() {
            this.$bus.$off('editName')
        },
    }
</script>
<style lang="">

</style>